<template>
  <view class="page-content">
    <!-- <u-navbar :custom-back='back' title="用户签名"></u-navbar> -->
    <gas-sign-canvas @uploadFn='onUpload' style="height: 100%"></gas-sign-canvas>
  </view>
</template>
<script>
import gasSignCanvas from './gas-canvas-sign/gas-canvas-sign.vue'
import env from '@/env'
  // const FormData = require('@/util/formData/formData.js')
  // import dictApi from '@/api/dict'
  // import upfileApi from '@/api/upfile'
  // import request from '@/util/request'
  // import enterHouseApi from '@/api/enterHouse'
  // import deliveryApi from '@/api/delivery'
  // import util from '@/util/common'
	export default {
    components: {
      gasSignCanvas
    },
		data() {
			return {
        
			}
		},

		onShow(op) {},

    onLoad(op) {
      // uni.setScreenOrientation({ orientation: 'landscape' })
    },

    created() {
    },

		methods: {
      setLandscape() {
        if (screen.lockOrientation) {
          screen.lockOrientation('landscape');
        } else if (screen.mozLockOrientation) {
          screen.mozLockOrientation('landscape');
        } else if (screen.msLockOrientation) {
          screen.msLockOrientation('landscape');
        }
      },
      /************************************************************ 
       * @description		后退方法
       * @author			hauner
       * @date			2023-12-06
       ************************************************************/
      back() {
        let url = this.$u.GlobalData.fromRoute
        this.$u.GlobalData.fromRoute = ''
        uni.showToast({ 'title': '签名成功' })
        setTimeout( () => {
          this.$u.route({ url, type: 'redirectTo', params: {fromSign: 1} })
        }, 500)
      },

      onUpload(file) {
        let maps = {
          dev: 'http://118.190.208.3:8888/',
          test: 'http://118.190.208.3:8888/',
          prod: 'http://106.116.245.184:8888/'
        }
        let service = maps[env] 
        let self = this
        let url = service + 'apis/fileManage/uploadFile'
        this.$u.toast('开始上传')
        uni.uploadFile({
          url,
          filePath:file,
          formData: {
            fileName: '签名',
            fileType: '1'
          },
          success({data, statusCode}){
            if(statusCode != 200) {
              self.$u.toast('上传失败', 'error');
              return;	
            }
            self.$u.GlobalData.signFile = data
            let url = self.$u.GlobalData.fromRoute
            self.$u.GlobalData.fromRoute = ''
            uni.showToast({ 'title': '签名成功' })
            self.$u.route({ url, type: 'redirectTo', params: {fromSign: 1} })
          },
          fail(e) {
            this.$u.toast(e, 'error');
          }
        })
        
        // let self = this
        // let fileObj = new FormData()
        // fileObj.appendFile('file', path)
        // let newData = fileObj.getData()
        // this.fileObj = fileObj 
        // upfileApi.upload(newData.buffer, newData.contentType).then(res => {
        //   self.$u.GlobalData.signFile = res
        //   let url = self.$u.GlobalData.fromRoute
        //   self.$u.GlobalData.fromRoute = ''
        //   uni.showToast({ 'title': '签名成功' })
        //   self.$u.route({ url, type: 'redirectTo', params: {fromSign: 1} })
        // }).catch(e => {
        //   uni.showToast({ 'title': '签名上传失败' })
        //   list.splice(ind,1)
        // })
      },  
    }
	}
</script>

<style lang='scss' scoped>
	.page-content {
    position: relative;
    // padding: 0 40rpx 120rpx;
    height: calc(100vh - 60rpx);
    .scan-list--item{
        padding: 20rpx;
        margin-bottom: 20rpx;
        border-radius: 20rpx;
        font-size: 24rpx;     
        .item-row{
          display: flex;
          align-items: center;
          margin-bottom: 20rpx;          
          .item-col{display: flex;flex: 1}
          
          .item-row--label{
            width: 100rpx;
            margin-right: 20rpx;
            color: #808285;
          }
          .item-row--value {
            flex: 1;
            word-wrap: overflow-wrap;
            word-break: break-all;
          }
        }
        
      }
    .blue-text{
      color: #157FEB;
      margin-right: 10rpx;
    }
    .scan-list--box{
      .scan-item-box{
        padding: 20rpx;
        margin-bottom: 20rpx;
        background: #F8F8FA;
        border-radius: 20rpx;
        font-size: 24rpx;
        .item-del-btn{
          color: #fa3534;
          font-size: 28rpx;
        }
        .item-row{
          display: flex;
          margin-bottom: 20rpx;
          .item-col{
            display: flex;
            flex: 1;
            .item-row--label{
              width: 140rpx;
              margin-right: 20rpx;
              color: #808285;
            }
          }
        }
      }
      .qr-scan--box{
        display: flex;
        align-items: center;
      }
    }
    .check-map-box{
      margin-top: 40rpx;
      .dite-map-title{
        margin-bottom: 40rpx;
      }
      .check-list-box .check-list-item{
        font-size: 24rpx;
        margin-top: 10rpx;
        display: flex;
        align-items: center;
        justify-content: space-between;
        .check-list-item-content{
          flex: 1;
          margin-right: 20rpx;
        }
      }
    }
    .check-list-item-check{font-size: 24rpx;}

    .sign-box{
      width: 100%;
      height: 320rpx;
      background: #FBFBFB;
      border-radius: 16px;
      display: flex;
      .sign-tip{
        margin: auto;
      }
    }
  }
</style>
